import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ShieLD } from './shield.entity';

@Injectable()
export class ShieLDService {
  constructor(
    @InjectRepository(ShieLD)
    private shieIdRepository: Repository<ShieLD>,
  ) {}

  findAll(): Promise<ShieLD[]> {
    return this.shieIdRepository.find();
  }

  findOne(id: number): Promise<ShieLD> {
    return this.shieIdRepository.findOne({where:{id}});
  }

  findOne_by_video_id(video_id: number, wx_user?: string): Promise<ShieLD> {
    return this.shieIdRepository.findOne({where:{video_id,wx_user}});
  }

  async remove(id: number): Promise<void> {
    await this.shieIdRepository.delete(id);
  }

  async remove_by_video_id(video_id: number, wx_user: string): Promise<void> {
    await this.shieIdRepository.delete({video_id, wx_user});
  }

  async create(shieId: ShieLD): Promise<void> {
    await this.shieIdRepository.save(shieId);
  }

  async update(shieId: ShieLD): Promise<void> {
    await this.shieIdRepository.save(shieId);
  }
}
